import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/config/index.dart';
import 'package:yp/helper.dart';
import 'package:yp/pages/mall_app/mall/logic.dart';
import 'package:yp/router.dart';
import 'package:yp/services/api.dart';

// import 'package:timelines/timelines.dart';

import 'logic.dart';
import 'state.dart';

class SelectShippingAddressPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _SelectShippingAddressPage();
  }
}

class _SelectShippingAddressPage extends State<SelectShippingAddressPage> {
  final SelectShippingAddressLogic logic =
      Get.put(SelectShippingAddressLogic());
  final SelectShippingAddressState state =
      Get.find<SelectShippingAddressLogic>().state;
  final MallLogic mallLogic = Get.put(MallLogic());

  bool show = false;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _surroundingSearch(null);
  }

  void _surroundingSearch(String keywords) {
    print('========= ${mallLogic.locationResult}  |  ${state.selectCityMap}');
    if (mallLogic.locationResult != null &&
        mallLogic.locationResult["AMapResult"] != null) {
      var aMapResult = mallLogic.locationResult["AMapResult"];
      var hasSelect = state.selectCityMap.isNotEmpty;
      print('hasSelect: $hasSelect');
      // var x = hasSelect
      //     ? state.selectCityMap['maplocation_x']
      //     : aMapResult["longitude"];
      // var y = hasSelect
      //     ? state.selectCityMap['maplocation_y']
      //     : aMapResult["latitude"];

      var x = aMapResult["longitude"];
      var y = aMapResult["latitude"];
      var city =
          hasSelect ? state.selectCityMap['city_name'] : aMapResult['city'];
      Map<String, dynamic> params = {
        "use_platform": 2,
        "maplocation_x": x,
        "maplocation_y": y,
        "city": city,
        "key_words": keywords
      };
      print('============$params');
      logic.surroundingSearch(params);
    } else {
      print('++++++++++++++++++');
      toast("未获取到当前位置");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        elevation: setWidth(1),
        backgroundColor: Colors.white,
        title: Text(
          '选择收货地址',
          style: TextStyle(
            color: Color(0xff030303),
            fontSize: 17,
          ),
        ),
        iconTheme: IconThemeData(
          color: Color(0xff333333),
        ),
        actions: [
          InkWell(
            onTap: () async {
              if (SpUtil.getString('token') != null &&
                  SpUtil.getString('token').isNotEmpty) {
                var success = await Get.toNamed(RouteConfig.addressCreate);
                print(
                    '+++++++++++++++------------****************  success = $success');
                if (success != null && success == true) {
                  logic.getReceivingAddressList();
                }
              } else {
                print('跳转登陆页面！！！');
                Get.toNamed(RouteConfig.mallLogin).then((value) {
                  logic.onInit();
                });
              }
            },
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: setWidth(18)),
              alignment: Alignment.center,
              // color: Colors.red,
              child: Text(
                '新增地址',
                style: TextStyle(
                  color: Color(0xffea5504),
                  fontSize: 15,
                ),
              ),
            ),
          ),
        ],
      ),
      body: GetBuilder<SelectShippingAddressLogic>(
        builder: (logic) {
          return Stack(
            children: [
              Column(
                children: [
                  Container(
                    height: setWidth(90),
                    color: Colors.white,
                    padding: EdgeInsets.symmetric(horizontal: setWidth(26)),
                    child: Row(
                      children: [
                        GestureDetector(
                            child: Row(children: [
                              // 这里打开注释 布局上会有错误
                              // GetX(
                              //   init: mallLogic,
                              //   builder: (mallLogic) {
                              //     return Text(
                              //       state.selectCityMap.isEmpty ? mallLogic.getAMapLocationCityName() : state.selectCityMap['city_name'],
                              //       style: TextStyle(
                              //         color: Color(0xff333333),
                              //         fontSize: 15,
                              //       ),
                              //     );
                              //   },
                              // ),
                              Text(
                                state.selectCityMap.isEmpty
                                    ? mallLogic.getAMapLocationCityName()
                                    : state.selectCityMap['city_name'],
                                style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: 15,
                                ),
                              ),
                              Padding(
                                  padding: EdgeInsets.symmetric(
                                      horizontal: setWidth(20)),
                                  child: Image.asset(
                                    'assets/images/icon-down.png',
                                    width: setWidth(20),
                                    height: setWidth(10),
                                    color: Color(0xffadadad),
                                    fit: BoxFit.cover,
                                  ))
                            ]),
                            onTap: () {
                              _dialog(Get.context);
                            }),
                        Expanded(
                          child: Container(
                            height: setWidth(54),
                            decoration: BoxDecoration(
                              color: Color(0xffF3F4F6),
                              borderRadius: BorderRadius.circular(setWidth(27)),
                            ),
                            child: Row(
                              children: [
                                Container(
                                  width: setWidth(58),
                                  height: setWidth(54),
                                  alignment: Alignment.center,
                                  child: Icon(
                                    Icons.search,
                                    size: setWidth(26),
                                    color: Color(0xffcccccc),
                                  ),
                                ),
                                Expanded(
                                  child: TextField(
                                    textAlignVertical: TextAlignVertical.bottom,
                                    // controller: TextEditingController(),
                                    decoration: InputDecoration(
                                        fillColor: Colors.transparent,
                                        border: OutlineInputBorder(
                                            borderSide: BorderSide.none),
                                        hintText: "搜索写字楼、小区",
                                        hintStyle: TextStyle(
                                            color: Color(0xffcccccc),
                                            fontSize: 14)),
                                    onChanged: (value) {
                                      if (value.isEmpty) {
                                        setState(() {
                                          show = false;
                                        });
                                      } else {
                                        setState(() {
                                          show = true;
                                        });
                                      }
                                      _surroundingSearch(value);
                                    },
                                    onSubmitted: (value) {
                                      _surroundingSearch(value);
                                    },
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                    child: show
                        ? GestureDetector(
                            onTap: () {
                              setState(() {
                                show = false;
                              });
                            },
                            child: Container(
                              width: 750.w,
                              padding: EdgeInsets.symmetric(vertical: 10),
                              decoration: BoxDecoration(
                                color: Colors.white,
                                border: Border(
                                  bottom: BorderSide(
                                    color: Colors.grey.withOpacity(.6),
                                  ),
                                ),
                              ),
                              child: ListView.builder(
                                shrinkWrap: true,
                                primary: true,
                                itemBuilder: (ctx, i) {
                                  var address = state.nearbyAddressList[i];
                                  if (i == 0 || address["name"] == null) {
                                    return Container();
                                  }
                                  return InkWell(
                                    child: Container(
                                      color: Colors.white,
                                      width: MediaQuery.of(context).size.width,
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: [
                                          Container(
                                            padding: EdgeInsets.only(
                                              left: setWidth(40),
                                              top: setWidth(30),
                                              right: setWidth(40),
                                              bottom: setWidth(40),
                                            ),
                                            child: Column(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                              children: [
                                                Text(
                                                  address["name"],
                                                  style: TextStyle(
                                                    color: Color(0xff333333),
                                                    fontWeight: FontWeight.bold,
                                                    fontSize: 14,
                                                  ),
                                                ),
                                                SizedBox(
                                                  height: setWidth(14),
                                                ),
                                                Text(
                                                  address["address"],
                                                  style: TextStyle(
                                                    color: Color(0xff333333),
                                                    fontSize: 14,
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                          Divider(
                                            height: setWidth(1),
                                            indent: setWidth(20),
                                            endIndent: 0,
                                            color: Color(0xffEFEFEF),
                                          ),
                                        ],
                                      ),
                                    ),
                                    onTap: () {
                                      if (!kIsWeb) {
                                        mallLogic.setUserSelectAddress(address);
                                      }
                                      Get.back();
                                    },
                                  );
                                },
                                itemCount: state.nearbyAddressList.length,
                              ),
                            ),
                          )
                        : ListView(
                            children: [
                              SizedBox(
                                height: setWidth(20),
                              ),
                              GetX(
                                init: mallLogic,
                                builder: (mallLogic) {
                                  return GestureDetector(
                                    onTap: () {
                                      print('当前位置！！！');
                                      if (!kIsWeb) {
                                        mallLogic.setCurrentPositionClick();
                                      }
                                      Get.back();
                                    },
                                    behavior: HitTestBehavior.opaque,
                                    child: Container(
                                      color: Colors.white,
                                      padding: EdgeInsets.only(
                                        left: setWidth(30),
                                        top: setWidth(40),
                                        right: setWidth(26),
                                        bottom: setWidth(50),
                                      ),
                                      child: Row(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        children: [
                                          Expanded(
                                            child: Column(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                              children: [
                                                Text(
                                                  '当前定位',
                                                  style: TextStyle(
                                                    color: Color(0xff9b9b9b),
                                                    fontSize: 14,
                                                  ),
                                                ),
                                                SizedBox(
                                                  height: setWidth(20),
                                                ),
                                                Text(
                                                  // mallLogic.getAMapLocationAddress(),
                                                  state.address??'',
                                                  style: TextStyle(
                                                    color: Color(0xff333333),
                                                    fontSize: 15,
                                                  ),
                                                )
                                              ],
                                            ),
                                          ),
                                          SizedBox(
                                            width: setWidth(30),
                                          ),
                                          mallLogic.isPositioning.value == true
                                              ? Container(
                                                  child: Row(
                                                    children: [
                                                      Container(
                                                        width: 10,
                                                        height: 10,
                                                        child:
                                                            CupertinoActivityIndicator(
                                                                radius: 8),
                                                      ),
                                                      Container(
                                                        margin: EdgeInsets.only(
                                                            left: 5),
                                                        child: Text(
                                                          "正在定位...",
                                                          style: TextStyle(
                                                            color: Color(
                                                                0xffea5504),
                                                            fontSize: 13,
                                                          ),
                                                        ),
                                                      )
                                                    ],
                                                  ),
                                                )
                                              : InkWell(
                                                  onTap: () =>
                                                      logic.getAddress(),
                                                  child: Container(
                                                    alignment:
                                                        Alignment.centerRight,
                                                    height: setWidth(80),
                                                    child: Text(
                                                      '重新定位',
                                                      style: TextStyle(
                                                        color:
                                                            Color(0xffea5504),
                                                        fontSize: 13,
                                                      ),
                                                    ),
                                                  ),
                                                ),
                                        ],
                                      ),
                                    ),
                                  );
                                },
                              ),
                              SizedBox(
                                height: setWidth(20),
                              ),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: state.receivingAddressList
                                        .asMap()
                                        .map((key, value) {
                                          if (key == 0) {
                                            return MapEntry(
                                              key,
                                              Stack(
                                                children: [
                                                  Container(
                                                    color: Colors.white,
                                                    child: Column(
                                                      children: [
                                                        Container(
                                                          width: MediaQuery.of(
                                                                  context)
                                                              .size
                                                              .width,
                                                          padding:
                                                              EdgeInsets.only(
                                                            left: setWidth(40),
                                                            top: setWidth(44),
                                                            right: setWidth(20),
                                                          ),
                                                          color: Colors.white,
                                                          child: Text(
                                                            '收货地址',
                                                            style: TextStyle(
                                                              color: Color(
                                                                  0xff9b9b9b),
                                                              fontSize: 14,
                                                            ),
                                                          ),
                                                        ),
                                                        logic.state.receivingAddressList
                                                                    .length ==
                                                                1
                                                            ? InkWell(
                                                                child:
                                                                    Container(
                                                                  child: Column(
                                                                    children: [
                                                                      Container(
                                                                          padding: EdgeInsets.only(
                                                                              top:
                                                                                  10),
                                                                          child:
                                                                              Divider(height: 1)),
                                                                      Container(
                                                                          padding: EdgeInsets.symmetric(
                                                                              vertical:
                                                                                  12),
                                                                          child:
                                                                              Text("新增地址")),
                                                                    ],
                                                                  ),
                                                                ),
                                                                onTap:
                                                                    () async {
                                                                  var success =
                                                                      await Get.toNamed(
                                                                          RouteConfig
                                                                              .addressCreate);
                                                                  if (success !=
                                                                          null &&
                                                                      success ==
                                                                          true) {
                                                                    logic
                                                                        .getReceivingAddressList();
                                                                  }
                                                                },
                                                              )
                                                            : Container(),
                                                      ],
                                                    ),
                                                  ),

                                                  // Positioned(
                                                  //   left: 0,
                                                  //   top: 0,
                                                  //   child: Image.asset(
                                                  //     'assets/images/selected_image.png',
                                                  //     width: setWidth(70),
                                                  //     height: setWidth(70),
                                                  //     fit: BoxFit.cover,
                                                  //   ),
                                                  // ),
                                                ],
                                              ),
                                            );
                                          } else if (key == 1 ||
                                              key == 2 ||
                                              key == 3) {
                                            return MapEntry(
                                              key,
                                              _addressWidget(
                                                index: key,
                                                address: value,
                                              ),
                                            );
                                          }
                                          // else if (key == state.receivingAddressList.length - 1) {
                                          //   return MapEntry(
                                          //     key,
                                          //     InkWell(
                                          //       onTap: () => Get.toNamed(RouteConfig.addressList),
                                          //       child: Container(
                                          //         width: MediaQuery.of(context).size.width,
                                          //         padding: EdgeInsets.only(
                                          //           top: setWidth(24),
                                          //           bottom: setWidth(24),
                                          //         ),
                                          //         color: Colors.white,
                                          //         alignment: Alignment.center,
                                          //         child: Text(
                                          //           '展开更多地址',
                                          //           style: TextStyle(
                                          //             color: Color(0xff9b9b9b),
                                          //             fontSize: 10,
                                          //           ),
                                          //         ),
                                          //       ),
                                          //     ),
                                          //   );
                                          // }
                                          return MapEntry(
                                            key,
                                            Container(),
                                          );
                                        })
                                        .values
                                        .toList(),
                                  ),
                                  state.receivingAddressList.length > 4
                                      ? InkWell(
                                          onTap: () => Get.toNamed(
                                                  RouteConfig.addressList)
                                              .then((value) {
                                            // print('==================== 返回数据 ===================  value = $value');
                                            if (value != null) {
                                              if (!kIsWeb) {
                                                var params = {
                                                  'access_token':
                                                      SpUtil.getString('token'),
                                                  'usr_num_id': SpUtil.getInt(
                                                      'empeNumId'),
                                                  'adr_num_id': value['address']
                                                      ['adr_num_id'],
                                                  'prv_num_id': value['address']
                                                      ['prv_num_id'],
                                                  'city_num_id':
                                                      value['address']
                                                          ['city_num_id'],
                                                  'city_area_num_id':
                                                      value['address']
                                                          ['city_area_num_id'],
                                                  'adr': value['address']
                                                      ['adr'],
                                                  'mobile': value['address']
                                                      ['contact_no'],
                                                  'receiver': value['address']
                                                      ['cont_empe'],
                                                  'default_sign': 1,
                                                };
                                                //获取选择商品列表数据
                                                Api.editAddressUpdate(params)
                                                    .listen((event) {
                                                  print(
                                                      '====== 获取选择商品列表数据 ======  event = $event');
                                                  mallLogic
                                                      .setUserSelectAddress(
                                                          value['address']);
                                                });
                                              }
                                              // mallLogic.setUserSelectAddress(value['address']);
                                            }
                                          }),
                                          child: Container(
                                            width: MediaQuery.of(context)
                                                .size
                                                .width,
                                            padding: EdgeInsets.only(
                                              top: setWidth(24),
                                              bottom: setWidth(24),
                                            ),
                                            color: Colors.white,
                                            alignment: Alignment.center,
                                            child: Text(
                                              '展开更多地址',
                                              style: TextStyle(
                                                color: Color(0xff9b9b9b),
                                                fontSize: 10,
                                              ),
                                            ),
                                          ),
                                        )
                                      : Container(),
                                ],
                              ),
                              SizedBox(
                                height: setWidth(20),
                              ),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: state.nearbyAddressList
                                    .asMap()
                                    .map((key, value) {
                                      return MapEntry(
                                          key,
                                          _nearbyAddressWidget(
                                              index: key, address: value));
                                    })
                                    .values
                                    .toList(),
                              ),
                            ],
                          ),
                  ),
                ],
              ),
            ],
          );
        },
      ),
    );
  }

  /// 地址address
  Widget _addressWidget({int index, Map address}) {
    bool showSelectIcon =
        logic.mapEquals(mallLogic.locationResult["userSelectAddress"], address);
    return Column(
      children: [
        InkWell(
          child: Container(
            color: Colors.white,
            padding: EdgeInsets.only(
              left: setWidth(40),
              top: setWidth(30),
              right: setWidth(20),
              bottom: setWidth(34),
            ),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(children: [
                        // 选中图标
                        showSelectIcon
                            ? Container(
                                margin: EdgeInsets.only(right: 10),
                                child: Image.asset(
                                    'assets/images/selected_image.png',
                                    width: setWidth(50)))
                            : Container(),
                        (address["address_tag"] ?? '') != ''
                            ? Container(
                                // width: setWidth(52),
                                // height: setWidth(24),
                                padding: EdgeInsets.symmetric(
                                  horizontal: 10.w,
                                  vertical: 1.w,
                                ),
                                decoration: BoxDecoration(
                                    color: Color(0xff1AEA5504),
                                    borderRadius:
                                        BorderRadius.circular(setWidth(2)),
                                    border: Border.all(
                                        color: Color(0xffea5504),
                                        width: setWidth(1))),
                                alignment: Alignment.center,
                                margin: EdgeInsets.only(right: setWidth(16)),
                                child: Text(
                                  address["address_tag"],
                                  style: TextStyle(
                                    color: Color(0xffEA5504),
                                    fontSize: 18.sp,
                                    height: 1.3,
                                  ),
                                ),
                              )
                            : Container(),
                        Expanded(
                            child: Text(
                                // "${address['prv_name']}${address['city_name']}${address['city_area_name']}${address['adr']}",
                                "${address['prv_name']} ${address['city_name']} ${address['city_area_name']}${address['town_name'] == null ? "" : " ${address['town_name']}"} ${address['adr']}",
                                maxLines: 3))
                      ], crossAxisAlignment: CrossAxisAlignment.start),
                      Padding(
                        child: Text(
                            "${address["cont_empe"]}  ${address["contact_no"]}",
                            style: TextStyle(
                              color: Color(0xff333333),
                              fontSize: 14,
                            )),
                        padding: EdgeInsets.only(left: 35),
                      ),
                      SizedBox(
                        height: setWidth(14),
                      )
                    ],
                  ),
                ),
                SizedBox(
                  width: setWidth(20),
                ),
                InkWell(
                  onTap: () async {
                    var success = await Get.toNamed(RouteConfig.addressUpdate,
                        arguments: address);
                    if (success != null && success == true) {
                      logic.getReceivingAddressList();
                    }
                  },
                  child: Container(
                    height: setWidth(70),
                    alignment: Alignment.centerRight,
                    child: Text(
                      '修改',
                      style: TextStyle(
                        color: Color(0xff9b9b9b),
                        fontSize: 12,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
          onTap: () {
            if (!kIsWeb) {
              var params = {
                'access_token': SpUtil.getString('token'),
                'usr_num_id': SpUtil.getInt('empeNumId'),
                'adr_num_id': address['adr_num_id'],
                'prv_num_id': address['prv_num_id'],
                'city_num_id': address['city_num_id'],
                'city_area_num_id': address['city_area_num_id'],
                'adr': address['adr'],
                'mobile': address['contact_no'],
                'receiver': address['cont_empe'],
                'default_sign': 1,
              };
              EasyLoading.show();
              //获取选择商品列表数据
              Api.editAddressUpdate(params).listen((event) {
                EasyLoading.dismiss();
                print('====== 获取选择商品列表数据 ======  event = $event');
                // if(event["code"].toString() == '0'){
                //   Get.back(result: true);
                // }
                mallLogic.setUserSelectAddress(address);
                Get.back();
              });
            } else {
              Get.back();
            }
          },
        ),
        Divider(
          height: setWidth(2),
          color: Color(0xffefefef),
          indent: setWidth(22),
          endIndent: 0,
        ),
      ],
    );
  }

  /// 附近地址
  Widget _nearbyAddressWidget({int index, Map address}) {
    return index == 0
        ? Container(
            color: Colors.white,
            width: MediaQuery.of(context).size.width,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  padding: EdgeInsets.only(
                    left: setWidth(40),
                    top: setWidth(44),
                    right: setWidth(20),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '附近地址',
                        style: TextStyle(
                          color: Color(0xff9B9B9B),
                          fontSize: 14,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          )
        : ((index == state.nearbyAddressList.length - 1)
            ? Container(
                color: Colors.white,
                width: MediaQuery.of(context).size.width,
                padding: EdgeInsets.only(
                  left: setWidth(40),
                  top: setWidth(30),
                  right: setWidth(40),
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    InkWell(
                      onTap: () {
                        //print('最多显示10条 点击事件！！！');
                      },
                      child: Container(
                        height: setWidth(80),
                        alignment: Alignment.center,
                        padding: EdgeInsets.only(
                          bottom: setWidth(5),
                        ),
                        child: Text(
                          '最多显示10条',
                          style: TextStyle(
                            color: Color(0xff9b9b9b),
                            fontSize: 10,
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              )
            : InkWell(
                child: Container(
                  color: Colors.white,
                  width: MediaQuery.of(context).size.width,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        padding: EdgeInsets.only(
                          left: setWidth(40),
                          top: setWidth(30),
                          right: setWidth(40),
                          bottom: setWidth(40),
                        ),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              address["name"],
                              style: TextStyle(
                                color: Color(0xff333333),
                                fontWeight: FontWeight.bold,
                                fontSize: 14,
                              ),
                            ),
                            SizedBox(
                              height: setWidth(14),
                            ),
                            Text(
                              address["address"],
                              style: TextStyle(
                                color: Color(0xff333333),
                                fontSize: 14,
                              ),
                            ),
                          ],
                        ),
                      ),
                      Divider(
                        height: setWidth(1),
                        indent: setWidth(20),
                        endIndent: 0,
                        color: Color(0xffEFEFEF),
                      ),
                    ],
                  ),
                ),
                onTap: () {
                  if (!kIsWeb) {
                    mallLogic.setUserSelectAddress(address);
                  }
                  Get.back();
                },
              ));
  }

  Future<Widget> _dialog(BuildContext context) {
    List<Widget> _items() {
      return state.cityList.map((item) {
        String cityId = '${item['city_num_id']}';
        var highlight = state.selectCityId == cityId;
        return GestureDetector(
          onTap: () {
            state.selectCityId = cityId;
            // 选择城市
            state.selectCityMap = item;
            print('========$item');
            Get.forceAppUpdate();
            Get.back();
          },
          child: Container(
            width: 150.w,
            padding: EdgeInsets.symmetric(vertical: 12),
            decoration: BoxDecoration(
                color: highlight ? EsColors.Primary : Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(4))),
            child: Center(
              child: Text(
                item['city_name'],
                style: TextStyle(
                  color: highlight ? Colors.white : Colors.black,
                  fontSize: 26.sp,
                ),
                maxLines: 1,
              ),
            ),
          ),
        );
      }).toList();
    }

    return showModalBottomSheet(
        context: context,
        enableDrag: false,
        backgroundColor: EsColors.BackGround,
        builder: (context) {
          return GestureDetector(
              onTap: () => Get.back(),
              child: Container(
                  constraints: BoxConstraints(minHeight: 200),
                  padding: EdgeInsets.all(8),
                  color: EsColors.BackGround,
                  child: Column(children: [
                    Container(
                        alignment: Alignment.centerLeft,
                        margin: EdgeInsets.symmetric(vertical: 12),
                        padding: EdgeInsets.only(left: 10),
                        child: Text('已开通服务的城市',
                            style: TextStyle(fontSize: EsSizes.MD))),
                    Expanded(
                      child: SingleChildScrollView(
                        child: Wrap(
                            children: _items(),
                            spacing: 18,
                            runSpacing: 20,
                            alignment: WrapAlignment.start),
                      ),
                    )
                  ])));
        });
  }
}
